/**********************************************************************************************************************************

"Foreign Aid and State Legitimacy: Evidence on Chinese and US Aid to Africa from Surveys, Survey Experiments, and Behavioral Games"
Robert A. Blair and Philip Roessler
World Politics
Replication Files

**********************************************************************************************************************************/

				
	
		clear
		clear matrix
		set more off
				
				
				
	// Set directory
					
		cd "[YOUR DIRECTORY]"

		
	
	// Load data
	
		use "survey_rural_data", clear
		

	
	// Define globals
		
		gl c_ctrls_census localitypop cwealth cliterate cnoschool cunemployed

		gl c_ctrls_ocha ocha_ofhouses ocha_school ocha_health ocha_wdaccessinwet ocha_cwardisable

		gl i_ctrls i_female i_age educ_abc educ_jh educ_hs employed rel_Muslim house_qual

		gl i_ctrls_fixed i_female i_age rel_Muslim

		gl district_FE district_FE1-district_FE15
		
		
xxx
	
	
	
	// Replicate figure 2, bottom panel
												
		reg itaxcomp_index_dum i.pstreat_alt $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4)) level(95) post				
				graph set window fontface "Times"
				marginsplot, recast(scatter) graphr(color(white)) plotopts(mcolor(black) msymbol(square)) ciopts(lcolor(black) lpattern(solid)) ///
					title("Rural survey sample", color(black) position(1)) ///
					xtitle("Treatment group", margin(medium)) xlabel(, angle(horizontal)) xscale(range(0.5(1)4.5)) ///
					ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
					xsize(4.4) ysize(3.26)
					gr_edit .xaxis1.edit_tick 5 1 `"(N = 145)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 6 2 `"(N = 183)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 7 3 `"(N = 174)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
					gr_edit .xaxis1.edit_tick 8 4 `"(N = 147)"', tickset(major) editstyle(tickstyle(textgap(4.6944)) )
			graph export "figure2_bottom.png", as(png) replace
						
						
						
	// Replicate table 2, bottom panel
											
		reg igov_support_index ichina_user iusa_user ichina_worker iusa_worker $i_ctrls_fixed $c_ctrls_census $district_FE, cl(towncode)
			outreg2 using "table2_bottom.tex", tex aster(se) lab dec(2) keep(ichina_user iusa_user ichina_worker iusa_worker) nocons replace
								
		reg demoliberia_satis ichina_user iusa_user ichina_worker iusa_worker $i_ctrls_fixed $c_ctrls_census $district_FE, robust cl(towncode)
			outreg2 using "table2_bottom.tex", tex aster(se) lab dec(2) keep(ichina_user iusa_user ichina_worker iusa_worker) nocons append

		foreach y of varlist refusetopay_yes taxauthoritypay_agree avoidpaytax_easy  {
			reg `y' ichina_user iusa_user ichina_worker iusa_worker $i_ctrls_fixed $c_ctrls_census $district_FE, robust cl(towncode)
			outreg2 using "table2_bottom.tex", tex aster(se) lab dec(2) keep(ichina_user iusa_user ichina_worker iusa_worker) nocons append
				}	
				
					

    // Replicate table A1, left panel
  	   
		preserve
		
		gl summstats ichinaprojects iusaprojects ichinause iusause ichinawork iusawork ichinaworkfriend iusaworkfriend ///
			igov_support_index demoliberia_satis refusetopay_yes taxauthoritypay_agree avoidpaytax_easy ///
			iobbad_agree iobpoor_agree iobeat_agree iobdonors_agree
	   
		order $summstats
			outreg2 using "tableA1_left.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 

		restore
		
		
		
    // Replicate table A3, left panel
		
		preserve
		
		gl summstats i_age rel_Christian educ_none educ_abc educ_hs readnews farmer
	   
		order $summstats
			outreg2 using "tableA3_left_col1.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 

		restore

		preserve
		
		keep if county=="Bong"

		gl summstats i_age rel_Christian educ_none educ_abc educ_hs readnews farmer

		order $summstats
			outreg2 using "tableA3_left_col2.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 
		
		restore

		preserve
		
		keep if county=="Lofa"

		gl summstats i_age rel_Christian educ_none educ_abc educ_hs readnews farmer

		order $summstats
			outreg2 using "tableA3_left_col2.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 
		
		restore

		preserve
		
		keep if county=="Nimba"

		gl summstats i_age rel_Christian educ_none educ_abc educ_hs readnews farmer

		order $summstats
			outreg2 using "tableA3_left_col3.tex", replace sum(log) keep($summstats) eqkeep(mean sd N) dec(2) tex label 
		
		restore
		
		
		
	// Replicate table A4
										
		mlogit pstreat_alt $i_ctrls $district_FE, cl(towncode)
			margins, dydx(*) predict(outcome(Control)) post
				outreg2 using "tableA4.tex", tex aster(se) dec(2) nocons keep($i_ctrls) ctitle(Control) label replace
		
		mlogit pstreat_alt $i_ctrls $district_FE, cl(towncode)
			margins, dydx(*) predict(outcome(Government)) post
				outreg2 using "tableA4.tex", tex aster(se) dec(2) nocons keep($i_ctrls) ctitle(Government) label append
		
		mlogit pstreat_alt $i_ctrls $district_FE, cl(towncode)
			margins, dydx(*) predict(outcome(China)) post
				outreg2 using "tableA4.tex", tex aster(se) dec(2) nocons keep($i_ctrls) ctitle(China) label append
		
		mlogit pstreat_alt $i_ctrls $district_FE, cl(towncode)
			margins, dydx(*) predict(outcome(USA)) post
				outreg2 using "tableA4.tex", tex aster(se) dec(2) nocons keep($i_ctrls) ctitle(USA) label append
				

		

		
	// Replicate table A7
				
		reg ichina_exposure_index dist_prj_status_completion_i10 dist_prj_status_planned_i10 $i_ctrls_fixed $c_ctrls_ocha, cl(towncode)
		test dist_prj_status_completion_i10 = dist_prj_status_planned_i10
			local p = round(r(p),.001)
				outreg2 using "tableA7.tex", tex aster(se) dec(2) keep(dist_prj_status_completion_i10 dist_prj_status_planned_i10) addtext(Completed vs. active p-value, `p') nocons replace

		foreach y of varlist ichina_user ichina_worker {
			reg `y' dist_prj_status_completion_i10 dist_prj_status_planned_i10 $i_ctrls_fixed $c_ctrls_ocha, robust cl(towncode)
				test dist_prj_status_completion_i10 = dist_prj_status_planned_i10
					local p = round(r(p),.001)
						outreg2 using "tableA7.tex", tex aster(se) dec(2) keep(dist_prj_status_completion_i10 dist_prj_status_planned_i10) addtext(Completed vs. active p-value, `p') nocons append
			}

			
				
				
	// Replicate table A8
				

		foreach y of varlist ichinaprojects ichinause ichinawork ichinaworkfriend {
			reg `y' dist_prj_status_completion_i10 dist_prj_status_planned_i10 $i_ctrls_fixed $c_ctrls_ocha, robust cl(towncode)
				test dist_prj_status_completion_i10 = dist_prj_status_planned_i10
					local p = round(r(p),.001)
						outreg2 using "tableA8.tex", tex aster(se) dec(2) keep(dist_prj_status_completion_i10 dist_prj_status_planned_i10) addtext(Completed vs. active p-value, `p') nocons append
			}

				

				
				
	// Replicate table A9

		reg igov_support_index dist_prj_status_completion_i10 dist_prj_status_planned_i10 $i_ctrls_fixed $c_ctrls_ocha, cl(towncode)
			test dist_prj_status_completion_i10 = dist_prj_status_planned_i10
				local p = round(r(p),.001)
					outreg2 using "tableA9.tex", tex aster(se) dec(2) keep(dist_prj_status_completion_i10 dist_prj_status_planned_i10) addtext(Completed vs. active p-value, `p') nocons replace

		foreach y of varlist demoliberia_satis refusetopay_yes taxauthoritypay_agree avoidpaytax_easy  {
			reg `y' dist_prj_status_completion_i10 dist_prj_status_planned_i10 $i_ctrls_fixed $c_ctrls_ocha, robust cl(towncode)
				test dist_prj_status_completion_i10 = dist_prj_status_planned_i10
					local p = round(r(p),.001)									
						outreg2 using "tableA9.tex", tex aster(se) dec(2) keep(dist_prj_status_completion_i10 dist_prj_status_planned_i10) addtext(Completed vs. active p-value, `p') nocons append
				}
			
			
			

	// Replicate figure A1, top panel
			
			cap matrix drop coefs
			cap matrix drop coefs1
			cap matrix drop coefs2

		reg itaxcomp_index_dum i.pstreat_alt i.kpelle i.pstreat_alt#i.kpelle $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4) kpelle=(0 1)) level(95) post

				matrix coefs = r(table)
				matrix colnames coefs = "Control" "Control" "Government" "Government" "China" "China" "USA" "USA"
				matselrc coefs coefs1 , r(1, 5, 6) c(1, 3, 5, 7)
				matselrc coefs coefs2 , r(1, 5, 6) c(2, 4, 6, 8)
		
			graph set window fontface "Times"
			coefplot (matrix(coefs1[1,]), ci((coefs1[2,] coefs1[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square)) ///
				(matrix(coefs2[1,]), ci((coefs2[2,] coefs2[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)), ///
				legend(on nostack position(6) cols(2)order(1 "No" 3 "Yes")) ///
				legend(subtitle("Kpelle")) ///
				xtitle("", margin(medsmall)) xlabel(, angle(horizontal)) xscale(range(0.5 4.5)) ///
				ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
				xsize(4.4) ysize(3.26) ///
				vertical

		graph export "figureA1_top.png", as(png) replace

					
	
	// Replicate figure A1, middle panel
		
			cap matrix drop coefs
			cap matrix drop coefs1
			cap matrix drop coefs2

		reg itaxcomp_index_dum i.pstreat_alt i.lorma i.pstreat_alt#i.lorma $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4) lorma=(0 1)) level(95) post

				matrix coefs = r(table)
				matrix colnames coefs = "Control" "Control" "Government" "Government" "China" "China" "USA" "USA"
				matselrc coefs coefs1 , r(1, 5, 6) c(1, 3, 5, 7)
				matselrc coefs coefs2 , r(1, 5, 6) c(2, 4, 6, 8)
		
			graph set window fontface "Times"
			coefplot (matrix(coefs1[1,]), ci((coefs1[2,] coefs1[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square)) ///
				(matrix(coefs2[1,]), ci((coefs2[2,] coefs2[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)), ///
				legend(on nostack position(6) cols(2)order(1 "No" 3 "Yes")) ///
				legend(subtitle("Lorma")) ///
				xtitle("", margin(medsmall)) xlabel(, angle(horizontal)) xscale(range(0.5 4.5)) ///
				ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
				xsize(4.4) ysize(3.26) ///
				vertical

		graph export "figureA1_middle.png", as(png) replace

								
			
	// Replicate figure A1, bottom panel
			
			cap matrix drop coefs
			cap matrix drop coefs1
			cap matrix drop coefs2

		reg itaxcomp_index_dum i.pstreat_alt i.mano i.pstreat_alt#i.mano $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4) mano=(0 1)) level(95) post

				matrix coefs = r(table)
				matrix colnames coefs = "Control" "Control" "Government" "Government" "China" "China" "USA" "USA"
				matselrc coefs coefs1 , r(1, 5, 6) c(1, 3, 5, 7)
				matselrc coefs coefs2 , r(1, 5, 6) c(2, 4, 6, 8)
		
			graph set window fontface "Times"
			coefplot (matrix(coefs1[1,]), ci((coefs1[2,] coefs1[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square)) ///
				(matrix(coefs2[1,]), ci((coefs2[2,] coefs2[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)), ///
				legend(on nostack position(6) cols(2)order(1 "No" 3 "Yes")) ///
				legend(subtitle("Mano")) ///
				xtitle("", margin(medsmall)) xlabel(, angle(horizontal)) xscale(range(0.5 4.5)) ///
				ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
				xsize(4.4) ysize(3.26) ///
				vertical

		graph export "figureA1_bottom.png", as(png) replace
		
		
		
		
	// Replicate figure A2
			
		reg itaxcomp_index_dum i.pstreat_alt c.war_viol i.pstreat#c.war_viol $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4) war_viol=(0(1)4)) level(95) post
														
					graph set window fontface "Times"
				marginsplot, by(pstreat) recast(scatter) ///
					plotopts(mcolor(black) msymbol(square)) ///
					subtitle(, fcolor(white) lstyle(color(black))) ///
					xtitle("Index of exposure to civil war violence", margin(medsmall)) xlabel(, angle(horizontal)) ///
					ytitle("Index of perceived obligation to pay taxes", margin(medsmall)) ylabel(0(1)4) ///
					xsize(4.4) ysize(3.26)				
						
					gr_edit .title.text = {}
					
					gr_edit .plotregion1.plotregion1[1].plot1.style.editstyle area(linestyle(color(black))) editcopy
					
					gr_edit .plotregion1.plotregion1[1].plot2.style.editstyle marker(fillcolor(black)) editcopy
					gr_edit .plotregion1.plotregion1[1].plot2.style.editstyle marker(linestyle(color(black))) editcopy
					gr_edit .plotregion1.plotregion1[1].plot2.style.editstyle line(color(black)) editcopy
					gr_edit .plotregion1.subtitle[1].style.editstyle linestyle(color(white)) editcopy
					
					gr_edit .style.editstyle boxstyle(shadestyle(color(white))) editcopy
					gr_edit .style.editstyle boxstyle(linestyle(color(white))) editcopy

				graph export "figureA2.png", as(png) replace


	
		
	
	// Replicate figure A3
			
			cap matrix drop coefs
			cap matrix drop coefs1
			cap matrix drop coefs2

		reg itaxcomp_index_dum i.pstreat_alt i.oppvote2011 i.pstreat#i.oppvote2011 $i_ctrls $c_ctrls_census $district_FE, cl(towncode)
			margins, atmeans at(pstreat_alt=(1(1)4) oppvote2011=(0 1)) level(95) post

				matrix coefs = r(table)
				matrix colnames coefs = "Control" "Control" "Government" "Government" "China" "China" "USA" "USA"
				matselrc coefs coefs1 , r(1, 5, 6) c(1, 3, 5, 7)
				matselrc coefs coefs2 , r(1, 5, 6) c(2, 4, 6, 8)
		
			graph set window fontface "Times"
			coefplot (matrix(coefs1[1,]), ci((coefs1[2,] coefs1[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(solid)) mcolor(black) msymbol(square)) ///
				(matrix(coefs2[1,]), ci((coefs2[2,] coefs2[3,])) graphr(color(white)) recast(scatter) ciopts(lcolor(black) lpattern(dash)) mcolor(black) msymbol(triangle)), ///
				legend(on nostack position(6) cols(2)order(1 "No" 3 "Yes")) ///
				legend(subtitle("Voted for opposition party in 2011")) ///
				xtitle("", margin(medsmall)) xlabel(, angle(horizontal)) xscale(range(0.5 4.5)) ///
				ytitle("Index of perceived obligation to pay taxes", margin(medsmall) size(medium)) ylabel(0(1)4) ///
				xsize(4.4) ysize(3.26) ///
				vertical

		graph export "figureA3.png", as(png) replace



					
